import { WhetherFollow } from "@/apis/consult"
import type { DoctorType, Knowledge } from "@/types/consult"
import { ref } from "vue"

//关注医生/文章的函数
export const useFollow = ()=>{
   const loading = ref(false)
   //不止涉及到关注医生，还有关注文章，所以在封装这种函数的时候要注意函数的复用性和适用性
   const whetherFollow = async (item: DoctorType | Knowledge) => {
    loading.value = true
    try {
      await WhetherFollow(item.id)
      item.likeFlag = item.likeFlag === 1 ? 0 : 1
    }
    finally {
      loading.value = false
    }
  }
  return {
    loading,
    whetherFollow
  }
}
